package com.atguigu.tingshu.user.receiver;

import com.alibaba.fastjson.JSON;
import com.atguigu.tingshu.common.constant.KafkaConstant;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * ClassName : UserReceiver
 * Package: com.atguigu.tingshu.user.receiver
 * Description:
 *
 * @Author 李轩辕
 * @Create 21/6/2024 下午7:45
 * @Version 17.0
 */
@Slf4j
@Component
public class UserReceiver {
    @Autowired
    private UserInfoService userInfoService;
    @KafkaListener(topics = KafkaConstant.QUEUE_USER_PAY_RECORD)
    public void updateUserPaidRecord(ConsumerRecord<String,String> record) {
        UserPaidRecordVo userPaidRecordVo = JSON.parseObject(record.value(), UserPaidRecordVo.class);
        log.info("更新用户支付记录: {}", JSON.toJSONString(userPaidRecordVo));
        //通知更新用户账号
        userInfoService.updateUserPaidRecord(userPaidRecordVo);
    }
}
